﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PSE.ProcessManager.Common.Gateway;

namespace PSE.ProcessManager.Server.InteligenceModules
{
    /// <summary>
    /// Inteligence Module utilizado para uma execução simples.
    /// </summary>
    public class SimpleExecutionInteligenceModule : BaseInteligenceModule
    {
		public SimpleExecutionInteligenceModule()
		{
			this.Executor = new SimpleExecutionProcessExecutor();
		}

		/// <summary> 
        /// Inicia a execução do processo.
        /// </summary>
        /// <param name="message"></param>
        public override void Execute(BaseMessage message)
        {
			base.Execute(message);

			SimpleExecutionProcessExecutor executor = (SimpleExecutionProcessExecutor)this.Executor;

			if (String.IsNullOrEmpty(message.Operation))
				throw new Exception();

            if (message.Operation.ToLower() == "execute")
                executor.Execute(message);
            else
            {
                executor.Gateway.BeginSendMessage(message);
            }
        }
    }
}
